package com.bysj.controller;

import com.bysj.entity.Goods;
import com.bysj.entity.News;
import com.bysj.service.NewsService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("news")
public class NewsController {
    @Autowired
    NewsService newsService;
    //查询所有数据
    @RequestMapping("/getNewsAll")
    @CrossOrigin
    public List<News> getAll(Map map){
        return newsService.getAll(map);
    }
    //按照id查询数据
    @RequestMapping("/selectNewsById")
    @CrossOrigin
    public List<News> selectById(Integer id){
        return newsService.selectById(id);
    }

    //根据id删除资讯
    @RequestMapping("/deleteNewsById")
    @ResponseBody
    @CrossOrigin
    public String deleteNewsById(Integer id){
        newsService.deleteNewsById(id);
        return "success";
    }
    //添加资讯
    @RequestMapping("/addNews")
    @ResponseBody
    @CrossOrigin
    public String addNews(@RequestBody News news){
        newsService.addNews(news);
        return "success";
    }

    //分页查询所有资讯
    @GetMapping("/getAllNewsByPage")
    @CrossOrigin
    public PageInfo<News> getAllNewsByPage(Map map,
                                             @RequestParam(defaultValue = "1") int pageNum,
                                             @RequestParam(defaultValue = "10") int pageSize ){
        PageInfo<News> newsList = newsService.getAllNewsByPage(map,pageNum,pageSize);
        return newsList;


    }


}
